#!/bin/bash

export PATH=${PATH}:/opt/yi/arm-linux-gnueabihf-4.8.3-201404/bin

export TARGET=arm-linux-gnueabihf
export CROSS=arm-linux-gnueabihf
export BUILD=x86_64-pc-linux-gnu

export CROSSPREFIX=${CROSS}-

export STRIP=${CROSSPREFIX}strip
export CXX=${CROSSPREFIX}g++
export CC=${CROSSPREFIX}gcc
export LD=${CROSSPREFIX}ld
export AS=${CROSSPREFIX}as
export AR=${CROSSPREFIX}ar
export LDFLAGS="-L`pwd`/dummylib -lOMX_AVQE_A"

SCRIPT_DIR=$(cd `dirname $0` && pwd)
cd $SCRIPT_DIR

make -C dummylib

cd libhelix-aac || exit 1
make clean
make -j $(nproc) || exit 1
mkdir ../live/lib/
cp -f ./libhelix-aac.a ../live/lib/
mkdir ../live/include/libhelix-aac
cp -f ./aaccommon.h ../live/include/libhelix-aac
cp -f ./aacdec.h ../live/include/libhelix-aac
cp -f ./statname.h ../live/include/libhelix-aac
cd ..

cd live || exit 1
make clean
make || exit 1

mkdir -p ../_install/bin || exit 1

cp ./rRTSPServer ../_install/bin/rRTSPServer || exit 1

arm-linux-gnueabihf-strip ../_install/bin/* || exit 1
